package com.java.simple.study.juc.p3;

import com.java.simple.study.tool.Sleeper;
import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.locks.LockSupport;

/**
 * @author zhoujl
 * @date 2022/5/9 20:53
 * @desc
 */
@Slf4j(topic = "c.TestLockSupport")
public class TestLockSupport {

    public static void main(String[] args) {
        //testParkUnpark();
        //testUnParkPark();
    }

    public static void testUnParkPark() {
        Thread t1 = new Thread(() -> {
            log.debug("start...");
            Sleeper.sleep(2);
            log.debug("park...");
            LockSupport.park();
            log.debug("resume...");
        }, "t1");
        t1.start();

        Sleeper.sleep(1);
        log.debug("unpark...");
        LockSupport.unpark(t1);
    }


    public static void testParkUnpark() {
        Thread t1 = new Thread(() -> {
            log.debug("start...");
            Sleeper.sleep(1);
            log.debug("park...");
            LockSupport.park();
            log.debug("resume...");
        }, "t1");
        t1.start();
        Sleeper.sleep(2);
        log.debug("unpark...");
        LockSupport.unpark(t1);
    }

}
